-
-
Notifications
You must be signed in to change notification settings - Fork 359
[Haskell] Barnsley Fern #851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Haskell] Barnsley Fern #851
Conversation
to_choice x = (+ 1) $ length $ takeWhile (x >) cumulProbabilities | ||
|
||
points = Point x y : zipWith (hutchinson !) (map to_choice picks) points | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{-
Here is alternative code with IO monad instead of explicit Random Generator.
You do random generation in sequence anyway (through g, g' and g''),
so why not let IO monad care about the sequential stuff for you?
Then you won't even need newStdGen in main function, you work in IO already.
(This is the code without taking into account my other comments)
chaosGame :: Int -> [Double] -> Array Int (Point -> Point) -> IO [Point]
chaosGame n probabilities hutchinson = do
x <- randomIO
y <- randomIO
picks <- replicateM n $ randomRIO (0, 1)
let cumulProbabilities = scanl1 (+) probabilities
to_choice x = (+ 1) $ length $ takeWhile (x >) cumulProbabilities
points = Point x y : zipWith (hutchinson !) (map to_choice picks) points
return points
-}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I usually try to stay away from IO
until the very end. I feel code is more portable when it's pure. Yes, it's true that I'm doing IO
in the end, but I want to focus more on the algorithm, and less on the task...
5d3dd07
to
67f2d3d
Compare
What do you think? Is this close to mergable? |
@leios I probed Seva a couple of times, but I guess he was too busy to check. He told before me that the initial code was already fine, and I've integrated all of his suggestions but one (with a valid reason) so I think this can be approved and merged, honestly. By you probably :) |
Ok, I thought that was what happened. Happy to merge it then! |
Seeing as #704 was reviewed recently, I'm pushing forward with Barnsley Fern.
I also fixed a typo in the chapter:
022
->0.22
.Output for 100k points:
